package com.electric.electric.serviceimpl;

import com.electric.electric.POJO.DTO.SecondaryIndicatorDTO;
import com.electric.electric.POJO.Entity.SecondaryIndicator;
import com.electric.electric.mapper.SecondaryIndicatorMapper;
import com.electric.electric.service.SecondaryIndicatorService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SecondaryIndicatorServiceImpl implements SecondaryIndicatorService {

    @Autowired
    private SecondaryIndicatorMapper secondaryIndicatorMapper;

    @Override
    public List<SecondaryIndicatorDTO> getAllSecondaryIndicators() {
        // 使用 selectList(null) 查询所有记录
        List<SecondaryIndicator> secondaryIndicators = secondaryIndicatorMapper.selectList();
        return secondaryIndicators.stream()
                .map(this::convertToDTO)
                .collect(Collectors.toList());
    }
    private SecondaryIndicatorDTO convertToDTO(SecondaryIndicator indicator) {
        SecondaryIndicatorDTO dto = new SecondaryIndicatorDTO();
        BeanUtils.copyProperties(indicator, dto);
        return dto;
    }
}